package ar.com.guess.image.utils;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import android.content.res.Resources;
import ar.com.guess.image.entities.Image;
import ar.com.guess.image.enums.Constant;
import ar.com.guess.image.enums.LanguagePlay;
import ar.com.guess.image.enums.Level;

/**
 * Builder de las images. Agarra el archivo resources y lo transforma en objetos Imagen.
 * 
 * @author Gatex
 *
 */
public abstract class ImageBuilder {
	
	private Image splitGuessImage(String imageMoreValue, Resources resources, String infoPackage ){
		String[] split = imageMoreValue.split(Constant.SEPARATOR_RESOURCE_VALUE.getValue());
		Image image = new Image(resources.getIdentifier(split[0],Constant.DRAWABLE.getValue(), infoPackage),split[1]);
    	return image;
    }
	
	public final LinkedList<Image> createImagesByLevel(Level level, LanguagePlay lang, Resources resources, String infoPackage){
		int identifierArray = resources.getIdentifier(transformerResource(level, lang), Constant.ARRAY.getValue(), infoPackage);
		String[] images = resources.getStringArray(identifierArray);
		LinkedList<Image> result = new LinkedList<Image>();
		for (String image : images) {
			result.add(splitGuessImage(image,resources,infoPackage));
		}
		Collections.shuffle(result);
		return result;
	}
	
	protected abstract String transformerResource(Level level, LanguagePlay lang);
}
